package scene.scene 
{
	import log.Log;
	import net.message.IMsgBody;
	/**
	 * ...
	 * @author carlor
	 */
	public class SceneManager 
	{
		private var _sceneList: Object;
		private var _curScene : SceneData;
		private var _msgProc  : Object;
		
		public function SceneManager() 
		{
			_sceneList = new Object();
			
		}
		
		public function setSceneMsgProc(value: Object): void
		{
			_msgProc   = value;
		}
		
		public function addScene(sceneName: String, scene: SceneData): void
		{
			if (_sceneList[sceneName]) return;
			_sceneList[sceneName] = scene;
		}
		
		public function deleteScene(sceneName: String): void
		{
			var result: SceneData = _sceneList[sceneName];
			delete _sceneList[sceneName];
			if (result) {
				result.dispose();
				result = null;
			}
		}
		
		public function getScene(sceneName: String): SceneData
		{
			return _sceneList[sceneName];
		}
		
		public function sceneActivate(sceneName: String): void
		{
			if (_curScene && _curScene.sceneName == sceneName) return;
			if (_curScene) _curScene.activate = false;
			if (_sceneList[sceneName]) {
				_sceneList[sceneName].activate = true;
			}
			_curScene = _sceneList[sceneName];
		}
		
		public function get activateScene(): SceneData
		{
			return _curScene;
		}
		
		public function handlePacket(op: String, msg: *): void
		{
			try {
				if (this._msgProc.hasOwnProperty(op))
					this._msgProc[op](msg);
			}catch (err: Error) {
				Log.errorLog(err.getStackTrace());
			}
		}
	}

}